<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html xmlns:th="" lang="zh-CN">
<%@include file="/WEB-INF/pages/base/include.jsp"%>
<body>
<div id="wrapper">
    <%@include file="/WEB-INF/pages/base/menu.jsp"%>
    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h3 class="page-header">商城管理</h3>
            </div>
        </div>
        <div class="row">
            <form class="form-horizontal" data-parsley-validate>
                <div class="col-lg-12 col-md-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">商城编辑</div>
                        <div class="panel-body">
                            <div class="row">
                                <div class="col-lg-12 col-md-12">
                                    <div class="form-group">
                                         <label class="col-lg-2 clo-md-2 control-label">商城id：</label>
                                         <div class="col-lg-8">
                                         	 <input type="text" id="mallId" value=""  readonly="readonly">
                                         </div>
                                     </div>
                                     <div class="form-group">
                                         <label class="col-lg-2 clo-md-2 control-label">商城名称：</label>
                                         <div class="col-lg-8">
                                         	 <input type="text" id="mallName" value=""  onkeyup = "ValidateValue(this)" >
                                         </div>
                                     </div>
                                     <div class="form-group">
                                         <label class="col-lg-2 clo-md-2 control-label">商城首页名称：</label>
                                         <div class="col-lg-8">
                                         	 <input type="text" id="companyName" value="" onkeyup = "ValidateValue(this)">
                                       	</div>
                                  	 </div>
                                     <div class="form-group">
                                         <label class="col-lg-2 clo-md-2 control-label">商城logo：</label>
                                         <div class="col-lg-8">
                                             <p><img id="mallLogo" src="" width="50px"></p>
                                             <button class="btn btn-default" id="photoUpload_1">上传图片</button>
                                         </div>
                                     </div>
                                     <div class="form-group no-filereader-hidden">
                                        <label class="col-sm-2 control-label"></label>
                                        <div class="col-sm-10">
                                            <div class="tag-wrapper" id="attachmentTag_1"></div>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                         <label class="col-lg-2 clo-md-2 control-label">商城色调：</label>
                                         <div class="col-lg-8">
                                         	 <input type="text" id="mallColor" value="">
                                       	</div>
                                  	 </div>
                                  	 <div class="form-group">
                                         <label class="col-lg-2 clo-md-2 control-label">联系电话：</label>
                                         <div class="col-lg-8">
                                        	 <input type="text" id="contactPhone" value=""  onkeyup="value=value.replace(/[^\d]/g,'')">
                                       	</div>
                                  	 </div>
                                  	 <div class="form-group">
                                         <label class="col-lg-2 clo-md-2 control-label">创建时间：</label>
                                         <div class="col-lg-8">
                                             <p id="createTime" ></p>
                                       	</div>
                                  	 </div>
                                   </div>
                               </div>
                           </div>
                       </div>
                   <div class="clearfix"></div>
                   <a class="btn btn-primary" href="javascript:void(0);"
                      style="margin-left:15px;margin-bottom:30px;" onclick="modify()">完成</a>
                   <a class="btn btn-default" href="${webPath}toUser"
                      style="margin-left:15px;margin-bottom:30px;">取消</a>
                </div>
            </form>
        </div>
    </div>
</div>
<script>	

	function ValidateValue(textbox) {
		var IllegalString = "[`~!#$^&*()=|{}':;',\\[\\].<>/?~！#￥……&*（）——|{}【】‘；：”“'。，、？]‘’";
		var textboxvalue = textbox.value;
		var index = textboxvalue.length - 1;
		var s = textbox.value.charAt(index);
		if (IllegalString.indexOf(s) >= 0) {
			s = textboxvalue.substring(0, index);
			textbox.value = s;
		}
	} 

   	$(function(){
		var mallId = "${mallId}";
  		var baseURL = "${webPath}/mall/detail";
      	var json_package = {
           "head": {},
           "body": {
           	"mallId": mallId
           }
       	}
   		$.post(baseURL, {"json_package": JSON.stringify(json_package)}, function (result) {
          if (typeof result == 'string') result = JSON.parse(result);
          if (result.body.result == '1') {
              alert(result.body.description)
          } else {
          	var mall = result.body.mall;
          	$("#mallId").val(mall.mallId);
          	$("#mallName").val(mall.mallName);
          	$("#mallLogo").attr('src',mall.mallLogo); 
          	$("#mallColor").val(mall.mallColor);
          	$("#companyName").val(mall.companyName);
          	$("#contactPhone").val(mall.contactPhone);
          	$("#createTime").text(mall.createTime);
          }
      	})
   	});
   	
   	(function(){
		var ajaxUpload = new AjaxUpload($('#photoUpload_1'), {
		    action: '${webPath}/file/uploadImage',
		    data: {
		        "json_package": JSON.stringify({
		            "head": {},
		            "body": {"file": "file"}
		        })
		    },
		    name: 'file',
		    onSubmit: function (file, ext) {
		        window.uploading = true;
		        $('#photoUpload_1').text('上传中...');
		        $('#photoUpload_1').attr('disabled', true);
		        this.disable();
		
		    },
		    onChange: function (file, extension) {
		        this.disable();
		    },
		    onComplete: function (file, response) {
		    	var data = JSON.parse(response);
		    	fileUrl = data.body.fileUrl;
		    	$("#mallLogo").attr('src',fileUrl); 
		        window.uploading = false;
		        $('#photoUpload_1').text('上传图片');
		        this.enable();
		    }
		});
	})();
   	
   	function modify() {
   		var mallId = "${mallId}";
   		var mallName = $("#mallName").val();
      	var mallLogo = $("#mallLogo")[0].src; 
      	var mallColor = $("#mallColor").val();
      	var companyName = $("#companyName").val();
      	var contactPhone = $("#contactPhone").val();

        if (contactPhone && (contactPhone.length < 8 || !(/([0-9]|[-])+/g.test(contactPhone)))) {
            alert('联系电话有误！');
            return;
        }
  		var baseURL = "${webPath}/mall/modify";
      	var json_package = {
           "head": {},
           "body": {
           	"mallId": mallId,
           	"mallName": mallName,
           	"mallLogo": mallLogo,
           	"mallColor":mallColor,
           	"companyName": companyName,
           	"contactPhone": contactPhone
           }
       	}
   		$.post(baseURL, {"json_package": JSON.stringify(json_package)}, function (result) {
          if (typeof result == 'string') result = JSON.parse(result);
          if (result.body.result == '1') {
              alert(result.body.description)
          } else {
        	  alert(result.body.description)
        	  location.href = "${webPath}toMall";
          }
      	});
	}
</script>
</body>
</html>
